package cn.rcth.controller;

import cn.rcth.base.VO.JsonResultVO;
import cn.rcth.base.domain.User;
import cn.rcth.base.serivce.ISendVerifyCodeService;
import cn.rcth.base.serivce.IUserSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 短信发送验证码
 */
@Controller
public class RegisterController {

    @Autowired
    private ISendVerifyCodeService sendVerifyCodeService;

    @Autowired
    private IUserSerivce userSerivce;



    @RequestMapping(value = "/sendVerifyCode",method = RequestMethod.GET)
    @ResponseBody//发送验证码
    public JsonResultVO sendVerifyCode(String phone){

        //查询当前手机号是否已经注册
        User user = userSerivce.ifPhone(phone);
       if (user == null){
           //执行发送验证码
           sendVerifyCodeService.sendVerifyCode(phone);
       }else{
           return JsonResultVO.error("手机号已被注册");
       }

        return JsonResultVO.success();
    }
}
